﻿using Abp.Authorization;
using Abp.Localization;
using Abp.MultiTenancy;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace Sunlit.Business.Authorization
{
    public class BusinessAuthorizationProvider : AuthorizationProvider
    {
        public override void SetPermissions(IPermissionDefinitionContext context)
        {
            var pages = context.GetPermissionOrNull(PermissionNames.Pages) ?? context.CreatePermission(PermissionNames.Pages, L("AllPermission"));

            pages.CreateChildPermission(PermissionNames.Pages_Users, L("Users"));
            pages.CreateChildPermission(PermissionNames.Pages_Roles, L("Roles"));
            pages.CreateChildPermission(PermissionNames.Pages_Tenants, L("Tenants"), multiTenancySides: MultiTenancySides.Host);

            pages.CreateChildPermission(PermissionNames.Pages_Policy, L("Policy"));
            pages.CreateChildPermission(PermissionNames.Pages_PolicyCate, L("PolicyCate"));

            pages.CreateChildPermission(PermissionNames.Pages_Enterprise, L("Enterprise"));
            pages.CreateChildPermission(PermissionNames.Pages_EnterpriseCate, L("EnterpriseCate"));

            pages.CreateChildPermission(PermissionNames.Pages_Commerce, L("Commerce"));
            pages.CreateChildPermission(PermissionNames.Pages_CommerceCate, L("CommerceCate"));

            pages.CreateChildPermission(PermissionNames.Pages_HomeSlider, L("HomeSlider"));
        }

        private static ILocalizableString L(string name)
        {
            return new LocalizableString(name, BusinessConsts.LocalizationSourceName);
        }
    }
}
